<template>
  <div class="container">
    <text class="big-title">示例</text>
    <div class="content">
      <text style="font-size: 28px; text-align: center;">上拉加载更多数据</text>
      <list class="list">
        <cell class="cell" v-for="item in listData" @click="listItemClick(item)">
          <text class="list-item">{{item.text}}</text>
          <div class="divider"></div>
        </cell>
        <loading @loading="onLoading" :display="showLoading">
          <text class="loading-text">加载中...</text>
        </loading>
      </list>
    </div>
    <text class="big-title">文档</text>
    <div class="button" @click="showDoc"><text class="btn-text">点击查看文档</text></div>
  </div>
</template>

<style scoped>
.container {
  padding: 10px;
}
.big-title {
  color: black;
  font-size: 50px;
  font-weight: bold;
  margin-bottom: 20px;
  margin-top: 20px;
}
.content {
  padding: 10px;
}
.list {
  height: 500px;
  border-width: 2px;
  border-color: #6699FF;
  border-radius: 8px;
  padding: 2px;
}
.list-item {
  padding-left: 15px;
  padding-top: 20px;
  padding-bottom: 20px;
  padding-right: 15px;
  font-size: 30px;
  color: #6699FF;
}
.cell {
  background-color: transparent;
}
.cell:active {
  background-color: #EFEFEF;
}
.loading-text {
  text-align: center;
  padding-top: 40px;
  padding-bottom: 40px;
  font-size: 30px;
  background-color: #EFEFEF;
}
.divider {
  height: 1.8px;
  background-color: #ECECEC;
}
.button {
  height: 60px;
  justify-content: center;
  opacity: 1.0;
}
.button:active {
  opacity: 0.6;
}
.btn-text {
  font-size: 30px;
  color: blue;
}
</style>

<script>
  import utils from '../utils.js';
  let modal = weex.requireModule('modal');
  let navigator = weex.requireModule('navigator');
  let arr = [];
  for (let i = 0; i < 20; i++) {
    arr.push({
      index: i,
      text: "list item " + i
    })
  }
  export default {
    data: {
      listData: arr,
      showLoading: 'hide'
    },
    methods: {
      onLoading() {
        modal.toast({message: 'loading...', duration: 1});
        this.showLoading = 'show';
        setTimeout(()=>{
          let count = this.listData.length;
          for (let i = 0; i < 3; i++) {
            this.listData.push({
              index: count + i,
              text: "new list item " + (count + i)
            })
          }
          this.showLoading = 'hide';
          modal.toast({message: 'load complete!', duration: 1});
        }, 2000);
      },
      listItemClick(item) {
        modal.toast({
          message: 'index: ' + item.index + ', content: ' + item.text,
          duration: 2
        })
      },
      showDoc() {
        navigator.push({
          url: utils.getDocDetailUrl(weex.config.bundleUrl),
          animated: true
        });
      }
    }
  }
</script>
